home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Programare / magiccd / mcdbc111t.exe / %MAINDIR% / C++ Builder / Unit1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-03-08  |  10.2 KB  |  315 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <stdio.h>
  4. #include "MCDBcls.h"
  5. #pragma hdrstop
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11.  
  12. char *status[] = {
  13.   " IDLE ",
  14.   " WRITING ",
  15.   " ERASING ",
  16.   " BACKGROUND FORMAT ",
  17.   " CLOSING TRACK ",
  18.   " PREPARING ",
  19.   " ABORTING ",
  20.   " IMPORTING SESSION ",
  21.   " BURN ERROR ABORTING "
  22. };
  23.  
  24. char mediums[15][14] = {
  25.   "mtUNKNOWN",
  26.   "mtCDROM",
  27.   "mtCDR",
  28.   "mtCDRW",
  29.   "mtDVDROM",
  30.   "mtDVDR",
  31.   "mtDVDRAM",
  32.   "mtDVDRW",
  33.   "mtDVDRWRO",
  34.   "mtDVDRWSR",
  35.   "mtDVDPLUSRW",
  36.   "mtDVDPLUSR",
  37.   "mtDDCDROM",
  38.   "mtDDCDR",
  39.   "mtDDCDRW"
  40. };
  41.  
  42. CMCDBurner mcdb;
  43.  
  44. void *MemoryFileHandle;
  45.  
  46. void __stdcall OnWriteDone(BOOL FAILED, void *arg);
  47.  
  48. //---------------------------------------------------------------------------
  49. __fastcall TForm1::TForm1(TComponent* Owner)
  50.         : TForm(Owner)
  51. {
  52. }
  53.  
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::FormCreate(TObject *Sender)
  56. {
  57.     int i;
  58.     for (i=0;i<mcdb.GetDeviceCount();i++)
  59.        cbDrives->Items->Add(mcdb.GetDeviceName(i));     // add the ava
  60.     if (cbDrives->Items->Count != 0)
  61.     {
  62.       cbDrives->ItemIndex = 0;
  63.       mcdb.SelectDevice(0);
  64.     }
  65.     mcdb.UnlockDrive();
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::cbDrivesChange(TObject *Sender)
  69. {
  70.     mcdb.SelectDevice(cbDrives->ItemIndex);
  71.     if (mcdb.DeviceIsBurner())
  72.       bBurn->Enabled = TRUE;
  73.     else
  74.       bBurn->Enabled = FALSE;
  75. }
  76. //---------------------------------------------------------------------------
  77.  
  78. void __fastcall TForm1::bEjectClick(TObject *Sender)
  79. {
  80.     mcdb.EjectMedium();
  81. }
  82. //---------------------------------------------------------------------------
  83.  
  84. void __fastcall TForm1::bBurnClick(TObject *Sender)
  85. {
  86.     int i;
  87.     String s;
  88.     wchar_t sss[100];
  89.     char sss2[256];
  90.     HANDLE hFind;
  91.     WIN32_FIND_DATA FindData;
  92.     mcdb.ClearAll();
  93. //    mcdb.SetBootImage("e:\\BootImage.img");
  94.     mcdb.SetVolumeID("Label3");
  95.     for (i=0;i<files->Items->Count;i++)
  96.     {
  97.       s = files->Items->Strings[i];
  98.       mbstowcs(sss, s.c_str(), strlen(s.c_str())+1);
  99.       if (DirectoryExists(s))
  100.       {
  101.          //mcdb.InsertDirW(L"\\", sss, L"*.*", True, cSavePath->Checked);  // // for unicode
  102.          mcdb.InsertDir("\\", s.c_str(), "*.*", True, cSavePath->Checked);
  103.  
  104.       }
  105.       else if (FileExists(s))
  106.       {
  107.          //mcdb.InsertFileW(L"\\", sss);  // for unicode
  108.          mcdb.InsertFile("\\", s.c_str());
  109. //         mcdb.InsertFileWithName("\\", s.c_str(), "New Long Name", "SHORTName");
  110.       }
  111.     }
  112.     if (cImportSession->Checked)
  113.       mcdb.ImportSession(0, "\\");
  114.     mcdb.Prepare();
  115.     /*
  116.     if (mcdb.BuildISOImage("c:\\abcc.iso", &OnWriteDone, (void *)this))   // to Build .ISO uncomment this line
  117.       Memo1->Lines->Add(">>> Building ISO Image ... ");
  118.     else
  119.     {
  120.       strcpy(sss2, ">>> BuildISOImage() Start Failed. Error (");
  121.       strcat(sss2, mcdb.GetErrorString());
  122.       strcat(sss2, ")");
  123.       Memo1->Lines->Add(sss2);
  124.     }
  125. /*
  126.      if (mcdb.BurnISOImage("c:\\abc.iso", &OnWriteDone, (void *)this))    // to Burn .ISO uncomment this line and comment mcdb.Prepare() (Above);
  127.     ;
  128.  
  129. */
  130.  
  131.     if (mcdb.Burn(&OnWriteDone, (void *)this) == TRUE)
  132.       Memo1->Lines->Add(">>> WRITING DISC ... ");
  133.     else
  134.     {
  135.       strcpy(sss2, ">>> Burn() Start Failed. Error (");
  136.       strcat(sss2, mcdb.GetErrorString());
  137.       strcat(sss2, ")");
  138.       Memo1->Lines->Add(sss2);
  139.     }
  140. }
  141. //---------------------------------------------------------------------------
  142.  
  143. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  144. {
  145.     double m, w;
  146.     char buf[64];
  147.     m = mcdb.GetImageSize();
  148.     w = mcdb.GetBlocksWritten();
  149.     pb->Max = m;
  150.     pb->Position = w;
  151.     if (mcdb.GetBlocksWritten() != 0)
  152.       sprintf(buf, "%4.2f/%4.2f MB (%0.0f%%)", (double )((w * 2048) / 1024 / 1024), (double )((m * 2048)/ 1024 / 1024), w / m * 100);
  153.     else
  154.       sprintf(buf, "%4.2f/%4.2f MB", (double )((w * 2048) / 1024 / 1024), (double )((m * 2048)/ 1024 / 1024));
  155.     lSize->Caption = buf;
  156.     m = mcdb.GetCacheSize();
  157.     w = mcdb.GetCachePosition();
  158.     scs->Max = m;
  159.     scs->Position = w;
  160.     m = mcdb.GetDeviceBufferSize();
  161.     w = mcdb.GetDeviceBufferPosition();
  162.     dbs->Max = m;
  163.     dbs->Position = w;
  164.     Label2->Caption = status[mcdb.GetComponentState()];
  165. }
  166. //---------------------------------------------------------------------------
  167. void __stdcall TForm1::OnWriteDone(BOOL FAILED, void *arg)
  168. {
  169.     TForm1 *Form1 = (TForm1 *) arg;
  170.     if (FAILED)
  171.     {
  172.       char sss2[256];
  173.       strcpy(sss2, ">>> WRITE DONE WITH ERROR (");
  174.       strcat(sss2, mcdb.GetErrorString());
  175.       strcat(sss2, ")");
  176.       Form1->Memo1->Lines->Add(sss2);
  177.     }
  178.     else
  179.       Form1->Memo1->Lines->Add(">>> WRITE DONE.");
  180. }
  181. //---------------------------------------------------------------------------
  182.  
  183. void _stdcall TForm1::OnEraseDone(BOOL FAILED, void *arg)
  184. {
  185.      TForm1 *Form1 = (TForm1 *) arg;
  186.      if (FAILED)
  187.        Form1->Memo1->Lines->Add(">>> ERASE DONE WITH ERROR");
  188.      else
  189.        Form1->Memo1->Lines->Add(">>> ERASEDISC DONE");
  190. }
  191.  
  192. //---------------------------------------------------------------------------
  193.  
  194. void __fastcall TForm1::bEraseClick(TObject *Sender)
  195. {
  196.    mcdb.TestUnitReady();
  197.    if (mcdb.TestUnitReady())
  198.    {
  199.       if (mcdb.Erasable())
  200.       {
  201.           Memo1->Lines->Add(">>> QUICK ERASING DISC ... ");
  202.           mcdb.EraseDisc(TRUE, &OnEraseDone, (void *)this);
  203.       }
  204.       else
  205.           Memo1->Lines->Add(">>> DISC IS NOT ERASABLE ... ");
  206.    }
  207.    else
  208.       Memo1->Lines->Add(">>> DRIVE NOT READY ... ");
  209. }
  210. //---------------------------------------------------------------------------
  211.  
  212. void __fastcall TForm1::bLoadClick(TObject *Sender)
  213. {
  214.     mcdb.LoadMedium();
  215. }
  216. //---------------------------------------------------------------------------
  217.  
  218.  
  219. void __fastcall TForm1::filesDragOver(TObject *Sender, TObject *Source,
  220.       int X, int Y, TDragState State, bool &Accept)
  221. {
  222.   Accept = Source->ClassNameIs("TDirectoryListBox") || Source->ClassNameIs("TFileListBox");        
  223. }
  224.  
  225. //---------------------------------------------------------------------------
  226.  
  227. void __fastcall TForm1::filesDragDrop(TObject *Sender, TObject *Source,
  228.       int X, int Y)
  229. {
  230.   int i;
  231.   String tmp;
  232.  
  233.   if(  Source->ClassNameIs("TDirectoryListBox"))
  234.   {
  235.     tmp = lbDir->GetItemPath(lbDir->ItemIndex);
  236.     if ( tmp[tmp.Length()] ==  '\\' )
  237.     {
  238.         tmp = tmp.SubString(0,tmp.Length()-1);
  239.     }
  240.     files->Items->Add(tmp);
  241.   }
  242.   if ((Source->ClassNameIs("TFileListBox")) )
  243.   {
  244.     for (i=0;i < lbFiles->Items->Count; i++)
  245.     {
  246.       if (lbFiles->Selected[i])
  247.       {
  248.         tmp = lbDir->Directory;
  249.         if ( tmp[tmp.Length()] == '\\' )
  250.         {
  251.            tmp = tmp.SubString(0,tmp.Length()-1);
  252.         }
  253.         tmp = tmp + '\\' + ExtractFileName(lbFiles->Items->Strings[i].c_str());
  254.         files->Items->Add(tmp);
  255.       }
  256.     }
  257.   }
  258.  
  259. }
  260. //---------------------------------------------------------------------------
  261.  
  262. void __fastcall TForm1::DeleteItem1Click(TObject *Sender)
  263. {
  264.   if (files->ItemIndex != -1)
  265.     files->Items->Delete(files->ItemIndex);
  266.  
  267. }
  268.  
  269. //---------------------------------------------------------------------------
  270.  
  271. void __fastcall TForm1::Button1Click(TObject *Sender)
  272. {
  273.    char tmpstr[100] = ">>> DISC IN DRIVE IS ";
  274.    strcat(tmpstr, mediums[mcdb.DiscIs()]);
  275.    Memo1->Lines->Add(">>> TestUnitReady(): "+IntToStr((__int64) mcdb.TestUnitReady()));
  276.    Memo1->Lines->Add(tmpstr);
  277.    Memo1->Lines->Add(">>> Erasable(): "+IntToStr((__int64) mcdb.Erasable()));
  278.    Memo1->Lines->Add(">>> Writable(): "+IntToStr((__int64) mcdb.Writable()));
  279.    Memo1->Lines->Add(">>> SessionsOnDisc(): "+IntToStr((__int64) mcdb.SessionsOnDisc()));
  280.    Memo1->Lines->Add(">>> GetTotalBlocksOnDisc(): "+IntToStr((__int64) (mcdb.GetTotalBlocksOnDisc() * 0.001953125) )+" MB");
  281.    Memo1->Lines->Add(">>> GetFreeBlocksOnDisc(): "+IntToStr((__int64) (mcdb.GetFreeBlocksOnDisc() * 0.001953125) )+" MB");
  282.    Memo1->Lines->Add(">>> DC_TEST_WRITE capable ? " + IntToStr(mcdb.DeviceCan(DC_TEST_WRITE)));
  283.    Memo1->Lines->Add(">>> DC_UNDERRUNPROTECTION capable ? " + IntToStr(mcdb.DeviceCan(DC_UNDERRUNPROTECTION)));
  284.    Memo1->Lines->Add(">>> READ_CDR capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_CDR)));
  285.    Memo1->Lines->Add(">>> READ_CDRW capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_CDRW)));
  286.    Memo1->Lines->Add(">>> READ_DVDRAM capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_DVDRAM)));
  287.    Memo1->Lines->Add(">>> READ_DVDR capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_DVDR)));
  288.    Memo1->Lines->Add(">>> READ_DVDRW capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_DVDRW)));
  289.    Memo1->Lines->Add(">>> READ_DVDPLUSR capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_DVDPLUSR)));
  290.    Memo1->Lines->Add(">>> READ_DVDPLUSRW capable ? " + IntToStr(mcdb.DeviceCan(DC_READ_DVDPLUSRW)));
  291.    Memo1->Lines->Add(">>> WRITE_CDR capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_CDR)));
  292.    Memo1->Lines->Add(">>> WRITE_CDRW capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_CDRW)));
  293.    Memo1->Lines->Add(">>> WRITE_DVDRAM capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_DVDRAM)));
  294.    Memo1->Lines->Add(">>> WRITE_DVDR capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_DVDR)));
  295.    Memo1->Lines->Add(">>> WRITE_DVDRW capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_DVDRW)));
  296.    Memo1->Lines->Add(">>> WRITE_DVDPLUSR capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_DVDPLUSR)));
  297.    Memo1->Lines->Add(">>> WRITE_DVDPLUSRW capable ? " + IntToStr(mcdb.DeviceCan(DC_WRITE_DVDPLUSRW)));
  298. }
  299. //---------------------------------------------------------------------------
  300.  
  301.  
  302.  
  303. void __fastcall TForm1::ClearAll1Click(TObject *Sender)
  304. {
  305.    Memo1->Lines->Clear();
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TForm1::Panel4Click(TObject *Sender)
  309. {
  310.   mcdb.AbortBurn();
  311. }
  312. //---------------------------------------------------------------------------
  313.  
  314.  
  315.